import { userGetUserInfoService } from '@/api/user'
import { defineStore } from 'pinia'
import { ref } from 'vue'

// 用户模块 token setToken removeToken
export const useUserStore = defineStore(
  'user',
  () => {
    const token = ref('')
    const setToken = (newToken) => {
      token.value = newToken
    }
    const user = ref({})
    const getUserInfo = async () => {
      const res = await userGetUserInfoService()
      user.value = res.data.data
      console.log(res.data.data)
    }
    const setUserInfo = (newUser) => {
      user.value = newUser
    }
    return { token, setToken, user, getUserInfo, setUserInfo }
  },
  {
    persist: true // 持久化
  }
)
